class SuccessPanel extends egret.Sprite
    {
    	private tap_textfeild : egret.TextField;
    	private rank_textfeild : egret.TextField;
    	private beat_textfeild : egret.TextField;
    	private title_textfeild : egret.TextField;
        private share_btn:egret.Bitmap;
        private replay_btn:egret.Bitmap;
        private titles_arr:string[] = ["剪刀手","等着挨骂吧","你真棒","纯爷们","真爷们"];
        private titles2_arr:string[] = ["坏男人","抠门","一毛不拔"];
        private titles3_arr:string[] = ["人称","铁公鸡"];
        private offheight:number = 40;
        public title_strs:string = "思维广";
        private yoffset :number;
        private yofftop :number;
		private  bg:egret.Bitmap;
    	public constructor() {
            super();
            this.yoffset = 288 + Main.stageH * 0.64;
            this.yoffset = this.yoffset > 800 ? 800 : this.yoffset;
            this.yofftop = 288 - Main.stageH * 0.36;
            this.yofftop = this.yofftop < 0 ? 0 : this.yofftop;
            this.bg = this.createBitmapByName("victory_bg");//开始按钮
            this.bg.y = this.yofftop + (Main.stageH - 625)/2 + 20;
			this.bg.x = 60;
            this.tap_textfeild= new egret.TextField();
	        this.tap_textfeild.width = 400;
	        this.tap_textfeild.textColor = 0xff0000;
        	this.tap_textfeild.textAlign = egret.HorizontalAlign.CENTER;
	        this.tap_textfeild.text = "您及时刹住了";
	        this.tap_textfeild.size = 22;
	        this.tap_textfeild.x = 80;
	        this.tap_textfeild.y = this.bg.y + 200;

	        this.rank_textfeild= new egret.TextField();
	        this.rank_textfeild.width = 400;
	        this.rank_textfeild.textColor = 0xffffff;
        	this.rank_textfeild.textAlign = egret.HorizontalAlign.CENTER;
	        this.rank_textfeild.text = "身手敏捷程度全国排名421位";
	        this.rank_textfeild.size = 22;
        	this.rank_textfeild.strokeColor = 0x000000;
        	this.rank_textfeild.stroke = 2;
	        this.rank_textfeild.x = 80;
	        this.rank_textfeild.y = this.tap_textfeild.y + this.offheight;

	        this.beat_textfeild= new egret.TextField();
	        this.beat_textfeild.width = 400;
	        this.beat_textfeild.textColor = 0xff0000;
        	this.beat_textfeild.textAlign = egret.HorizontalAlign.CENTER;
	        this.beat_textfeild.size = 22;
	        this.beat_textfeild.text = "击败了80%的老公";
	        this.beat_textfeild.x = 80;
	        this.beat_textfeild.y = this.rank_textfeild.y + this.offheight;

	        this.title_textfeild= new egret.TextField();
	        this.title_textfeild.width = 400;
	        this.title_textfeild.textColor = 0xff0000;
        	this.title_textfeild.textAlign = egret.HorizontalAlign.CENTER;
	        this.title_textfeild.size = 24;
	        this.title_textfeild.text = "获得称号：思维广";
	        this.title_textfeild.x = 80;
	        this.title_textfeild.y = this.beat_textfeild.y + this.offheight;


	        this.share_btn = this.createBitmapByName("share_btn");//开始按钮
            this.share_btn.x = 70
            this.share_btn.y = this.bg.height + 20 + this.bg.y;
            this.share_btn.touchEnabled = true;//开启触碰
            this.share_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.doShare,this);//点击按钮开始游戏
            
	        this.replay_btn = this.createBitmapByName("replay_btn");//开始按钮
            this.replay_btn.x = 280
            this.replay_btn.y = this.bg.height + 20 + this.bg.y;
            this.replay_btn.touchEnabled = true;//开启触碰
            this.replay_btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.doRepaly,this);//点击按钮开始游戏

            this.addChild(this.bg);
	        this.addChild(this.tap_textfeild);
	        this.addChild(this.rank_textfeild);
	        this.addChild(this.beat_textfeild);
	        this.addChild(this.title_textfeild);
	        this.addChild(this.share_btn);
	        this.addChild(this.replay_btn);
        }

        public score(n : number,isWin:number){

			if(isWin>0){
				this.tap_textfeild.text = "您用"+n+"秒就剁掉了你老婆的手";

				var scores:number = 0;
				if(n<=4){
					scores = 95;
					this.rank_textfeild.text = "为您省下10元大洋，分享即可获得啦";
					this.title_textfeild.text = "击败了"+scores+"%的老公";
				}else if(n<=8){
					scores = 40;
					this.rank_textfeild.text = "击败了"+scores+"%的老公";
					this.title_textfeild.text="";
				}else{
					scores = 10;
					this.rank_textfeild.text = "击败了"+scores+"%的老公";
					this.title_textfeild.text="";
				}
				this.beat_textfeild.text = "获得称号:铁公鸡老公";
				var texture:egret.Texture = RES.getRes("failed_bg");
				this.bg.texture = texture;
			}else{
				this.tap_textfeild.text = "您用"+n+"秒才剁掉你老婆的手";
				this.rank_textfeild.text = "老婆败家成功！！！";
				this.title_textfeild.text = "";
				this.beat_textfeild.text = "获得称号:中国好老公";
				var texture:egret.Texture = RES.getRes("victory_bg");
				this.bg.texture = texture;
			}

        	//this.rank_textfeild.text = "身手敏捷程度全国排名"+ Math.floor(n*1234678 + Math.random()* n*500) +"位";
        	//this.beat_textfeild.text = "击败了"+(100-Math.floor(n*Math.random()))+"%的老公";
			/*
            var title_str: string;
            if(n < 15){
                title_str = this.titles_arr[Math.floor(Math.random()*this.titles_arr.length)];
            }else if(n<20){
                title_str = this.titles2_arr[Math.floor(Math.random()*this.titles2_arr.length)];
            }else{
                title_str = this.titles3_arr[Math.floor(Math.random()*this.titles3_arr.length)];
            }
	        this.title_textfeild.text = "获得称号：" +title_str;
	        */
            //this.title_strs=title_str;
        }

        public doShare(evt:egret.TouchEvent):void{
      		this.dispatchEventWith("shareEvent");
        }

        public doRepaly(evt:egret.TouchEvent):void{
      		this.dispatchEventWith("replayEvent");
        }

        private createBitmapByName(name:string):egret.Bitmap {
            var result:egret.Bitmap = new egret.Bitmap();
            var texture:egret.Texture = RES.getRes(name);
            result.texture = texture;
            return result;
        }
    }